package com.imooc.ecommerce.service.communication;

import com.imooc.ecommerce.service.communication.hystrix.AuthorityFeignClientFallback;
import com.imooc.ecommerce.service.communication.hystrix.AuthorityFeignClientFallbackFactory;
import com.imooc.ecommerce.vo.JwtToken;
import com.imooc.ecommerce.vo.UsernameAndPassword;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * <p>与 Authority 服务通信的 Feign Client 接口定义
 *
 * @author Yaxi.Zhang
 * @since 2022/11/13 00:33
 */
@FeignClient(
        contextId = "AuthorityFeignClient", // contextId: 唯一标识，当有多个接口对应同一个serviceId时可以通过该属性进行区分，没有指定时，一个serviceId只能指定一个Feign接口
        value = "e-commerce-authority-center", // value: 需要通信的微服务的serviceId（注册中心中的id）
        // fallback = AuthorityFeignClientFallback.class,
        fallbackFactory = AuthorityFeignClientFallbackFactory.class
)
public interface AuthorityFeignClient {
    /**
     * <p>通过 OpenFeign 访问 Authority 获取 Token
     */
    @RequestMapping(value = "/ecommerce-authority-center/authority/token",
            method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
    JwtToken getTokenByFeign(@RequestBody UsernameAndPassword usernameAndPassword);

}
